package com.zm.demo.core.jvm;

import com.sun.management.OperatingSystemMXBean;

import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;

/**
 * @author z01140
 * @Package: com.zm.demo.core.jvm
 * @Description:
 * @CreateDate 2023/9/5 17:33
 * @UpdateDate 2023/9/5 17:33
 */
public class JVMMetrics {

    public static void main(String[] args) {


        OperatingSystemMXBean systemMXBean = (OperatingSystemMXBean)ManagementFactory.getOperatingSystemMXBean();
        System.out.println(systemMXBean.getArch());
        System.out.println(systemMXBean.getSystemCpuLoad());
        System.out.println(systemMXBean.getName());
        System.out.println(systemMXBean.getProcessCpuLoad());
        System.out.println(systemMXBean.getSystemLoadAverage());
        System.out.println(systemMXBean.getVersion());
        System.out.println(systemMXBean.getProcessCpuTime());
        String[] a = new String[10000];
        for (int i = 0; i < a.length; i++) {
            a[i] = i+"dasdas阿斯顿撒旦";
        }
        MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
        System.out.println(memoryMXBean.getHeapMemoryUsage().getUsed());
        System.out.println(memoryMXBean.getNonHeapMemoryUsage().getUsed());
    }
}
